package com.wesley.future.Utils;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import com.wesley.future.Model.Usuario;

public class HibernateUtil {
	private static SessionFactory sessionFactory;
	
	private HibernateUtil(){
	}
	
	public static SessionFactory getSessionFactory(){
		if (sessionFactory == null){
			try{
				AnnotationConfiguration ac = new AnnotationConfiguration();
				ac.addAnnotatedClass(Usuario.class);
				sessionFactory = ac.configure().buildSessionFactory();
			} catch (Throwable ex){
				System.err.print("Initial SessionFactory creation failed." + ex);
				
				throw new ExceptionInInitializerError(ex);
			}
			return sessionFactory;
		
		}else {
			return sessionFactory;
		}
	}

}
